<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .biao {
            margin: 0 auto;
            text-align: center;
            border-collapse: collapse;
        }
        
        .biao,
        th,
        tr,
        td {
            border-bottom: 1px solid #ccc;
        }
        
        .biao td {
            width: 80px;
        }
        
        .biao th {
            border-top: 1px solid #ccc;
            background-color: aquamarine;
        }
        
        .bg {
            background-color: pink;
        }
    </style>
</head>

<body>
    <table class="biao">
        <thead>
            <tr>
                <th>表头1</th>
                <th>表头2</th>
                <th>表头3</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>行1.1</td>
                <td>行1.2</td>
                <td>行1.3</td>
            </tr>
            <tr>
                <td>行2.1</td>
                <td>行2.2</td>
                <td>行2.3</td>
            </tr>
            <tr>
                <td>行3.1</td>
                <td>行3.2</td>
                <td>行3.3</td>
            </tr>
            <tr>
                <td>行4.1</td>
                <td>行4.2</td>
                <td>行4.3</td>
            </tr>
        </tbody>
    </table>
    <script>
        //1.获取tbody里的元素
        var trs = document.querySelector("tbody").querySelectorAll("tr");
        //2.循环注册绑定事件
        for (var i = 0; i < trs.length; i++) {
            //鼠标经过事件
            trs[i].onmouseover = function() {
                    // console.log(1);
                    this.className = ("bg");
                }
                //鼠标离开事件
            trs[i].onmouseout = function() {
                this.className = "";
            }
        }
    </script>
</body>

</html>